Literate Programming
Literate programming is a programming methodology developed by Donald Knuth in the early 1980s that fundamentally reverses the traditional relationship between code and documentation. In traditional programming, code is primary and comments are secondary annotations. In literate programming, human-readable documentation is primary, with code embedded within it. The programmer writes what essentially amounts to an essay explaining the program, with code snippets included where appropriate.
Important aspects of this approach:
- Programs as literature: Writing programs to be read by humans first, computers second
- Psychological order vs. computer order: Organizing code in an order that makes sense to human understanding, rather than what the compiler requires
- Web of code chunks: Breaking code into named, logical sections that can be referenced and reused
Literate programming tools typically process source files in two ways:
- “Weaving” to produce human-readable documentation
- “Tangling” to extract and reorganize the embedded code into something a compiler can process
References
Knuth, Donald Ervin. Literate Programming. Repr. CSLI Lecture Notes 27. Stanford: CSLI, 2001.
Krajewski, Markus. “Kulturtechnik Programmieren. Quellcode kritisieren. Drei Beispielszenarien.” In Quellcodekritik: zur Philologie von Algorithmen, edited by Hannes Bajohr and Markus Krajewski, Erste Auflage., 63–86. August Akademie. Berlin: August Verlag, 2024.
“Literate Programming.” In Wikipedia, April 23, 2025. https://en.wikipedia.org/w/index.php?title=Literate_programming&oldid=1287059289.